package com.zggk.lzz.sjxq;


import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.zggk.lzz.R;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.mvp.MVPBaseActivity;
import com.zggk.lzz.util.NoScroolGridView;
import com.zggk.lzz.util.ShowGridAdapter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class SjxqActivity extends MVPBaseActivity<SjxqContract.View, SjxqPresenter> implements SjxqContract.View {


    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.sbr_te)
    TextView sbrTe;
    @Bind(R.id.lxbm_lay)
    LinearLayout lxbmLay;
    @Bind(R.id.fxsj_te)
    TextView fxsjTe;
    @Bind(R.id.fxdd_te)
    TextView fxddTe;
    @Bind(R.id.sjzt_te)
    TextView sjztTe;
    @Bind(R.id.sjlx_te)
    TextView sjlxTe;
    @Bind(R.id.czfs_te)
    TextView czfsTe;
    @Bind(R.id.add_pic_grid)
    NoScroolGridView addPicGrid;
    @Bind(R.id.add_pic_lay)
    LinearLayout addPicLay;
    @Bind(R.id.activity_disease_new_scrollview)
    ScrollView activityDiseaseNewScrollview;
    @Bind(R.id.disease_new_parent_layout)
    RelativeLayout diseaseNewParentLayout;

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_sjxq;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        setTitleText("事件详情");
        goBack();
        initData();
    }

    private void initData() {
        mPresenter.getData(getIntent().getStringExtra("id"), SjxqActivity.this);
    }

    @Override
    public void getDatas(SjxqBean.DataBean dataBean) {
        sbrTe.setText(dataBean.getRecords().getCreateUserName());
        fxsjTe.setText(getDateTimeFromMillisecond(dataBean.getRecords().getCreateTime()));
        fxddTe.setText(dataBean.getRecords().getFindadress());
        sjztTe.setText(dataBean.getRecords().getState());
        sjlxTe.setText(dataBean.getRecords().getEtype());
        czfsTe.setText(dataBean.getRecords().getDoinfo());
        ArrayList<String> listImgUrl = new ArrayList<>();
        if (dataBean.getRecords().getPic() != null && dataBean.getRecords().getPic().size() > 0) {
            for (int i = 0; i < dataBean.getRecords().getPic().size(); i++) {
                listImgUrl.add(Urls.JAVASERVER + "pms/rhms/lzzapp/getImage?id=" + dataBean.getRecords().getPic().get(i).getPicId() + "&token=Bearer$" + MyApplication.spUtils.getString("Token"));
            }
        }
        ShowGridAdapter showGridAdapter = new ShowGridAdapter(this, listImgUrl);
        addPicGrid.setAdapter(showGridAdapter);
    }
    public static String getDateTimeFromMillisecond(String millisecond) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ");
        Date date = new Date();
        try {
            date = sdf.parse(millisecond);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String sDate=sdf2.format(date);
        return sDate;
    }
}
